<!DOCTYPE html>
<html lang="cn">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>

<body>
    <h1>1</h1>
    <button>点击</button>
    <input type="text">
    <script>
        let obj = {};
        let name = '';
        Object.defineProperty(obj, "name", {
            get() {
                return name;
            },
            set(value) {
                $('h1').text(value)
                name = value;
            }
        })
        let num = 0;
        // $('button').click(function () {
        //     obj.name = num++;
        //     // $('input').val($('h1').val());
        //     $('input').val(obj.name);

        //     // console.log(obj.name);
        // })
        $('input').on('input', function () {
            obj.name = $(this).val();
        })
    </script>
</body>

</html>